package com.zuo.mall.service.impl;

import cn.hutool.core.util.PageUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zuo.mall.common.api.CommonPage;
import com.zuo.mall.entity.OmsOrderReturnReason;
import com.zuo.mall.mapper.OmsOrderReturnReasonMapper;
import com.zuo.mall.service.OmsOrderReturnReasonService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OmsOrderReturnReasonServiceImpl extends ServiceImpl<OmsOrderReturnReasonMapper, OmsOrderReturnReason> implements OmsOrderReturnReasonService {
    @Override
    public CommonPage<OmsOrderReturnReason> list(Integer pageNum, Integer pageSize) {
        LambdaQueryWrapper<OmsOrderReturnReason> queryWrapper = new LambdaQueryWrapper<>();


        queryWrapper.orderBy(true, false, OmsOrderReturnReason::getSort);
        Integer count = baseMapper.selectCount(queryWrapper);
        queryWrapper.last("LIMIT "+ PageUtil.getStart(pageNum - 1, pageSize) + ", " + pageSize);
        List<OmsOrderReturnReason> orderReturnReasonList =
                baseMapper.selectList(queryWrapper);

        return CommonPage.restPage(orderReturnReasonList, Long.valueOf(count), pageSize);
    }

    @Override
    public int updateStatusBatch(List<Long> ids, Integer status) {
        LambdaUpdateWrapper<OmsOrderReturnReason> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(OmsOrderReturnReason::getStatus, status);
        updateWrapper.in(OmsOrderReturnReason::getId, ids);
        boolean update = this.update(updateWrapper);
        return update?ids.size():0;
    }
}
